package xyz.lwm.lazycat.aop.info;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import xyz.lwm.lazycat.utility.reflect.AnnotationUtil;
import xyz.lwm.lazycat.utility.reflect.Annotations;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

class SimpleMethodInfo implements MethodInfo {

    @Getter
    private final Method method;

    private final String methodName;

    @Getter
    private final String[] annotationNames;

    @Getter
    private final Annotations annotations;

    @Getter
    private final ClassInfo classInfo;

    SimpleMethodInfo(Method method, ClassInfo classInfo) {
        this.method = method;
        this.methodName = method.getName();
        this.annotationNames = Arrays.stream(AnnotationUtil.getAnnotations(method).getAnnotations())
                .map(Annotation::annotationType).map(Class::getName).toArray(String[]::new);
        this.annotations = AnnotationUtil.getAnnotations(method);
        this.classInfo = classInfo;
    }

    @NotNull
    @Override
    public String getName() {
        return methodName;
    }

}